package com.icecola.d1_create_thread;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

//方式三 实现Callable接口
//优点：可以得到返回值
public class ThreadTest3 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //封装Callable对象为线程对象
        MyCallable myCallable = new MyCallable(100);

        FutureTask<String> stringFutureTask = new FutureTask<>(myCallable);
        new Thread(stringFutureTask).start();
        MyCallable myCallable2 = new MyCallable(200);

        FutureTask<String> stringFutureTask2 = new FutureTask<>(myCallable2);
        new Thread(stringFutureTask2).start();
        String rs =stringFutureTask.get();
        System.out.println(rs);
        String rs2 =stringFutureTask2.get();
        System.out.println(rs2);

    }
}
